package main

import "fmt"
import "os"
import "strconv"
import "simplemath"

var Usage = func() {
    fmt.Println("USAGE: calc command [arguments] ...")
    fmt.Println("\nThe command are:\n\tadd\tAddition of two value.\n\tsqrt\tSqure root of a non-negative value")
}

func main() {
    args := os.Args
    if args == nil || len(args) < 2 {
        Usage()
        return
    }

    switch args[1] {
        case "add":
            if len(args) != 4 {
                fmt.Println("Usage: calc add <integer1> <integer2>");
                return
            }
            v1, err1 := strconv.Atoi(args[2])
            v2, err2 := strconv.Atoi(args[3])
            if err1 != nil && err2 != nil {
                fmt.Println("Usage: calc add <integer1> <integer2>");
                return
            }
            v := simplemath.Add(v1, v2)
            fmt.Printf("Result: %d\n", v);
        case "sqrt":
            if len(args) != 3 {
                fmt.Println("Usage: calc sqrt <integer>")
                return
            }
            v, err := strconv.Atoi(args[2])
            if err != nil {
                fmt.Println("Usage: calc sqrt <integer>")
                return
            }
            ret := simplemath.Sqrt(v)
            fmt.Printf("Result: %d\n", ret);
        default:
            Usage()
    }
}
